 /* qConsole.js (qJSLib)
 
    @Summary    : Full Featured Logging console for qJSLib
    @Author     : Timothy C. Quinn
    @License    : http://www.opensource.org/licenses/mit-license.php
    
    @Dependencies:
     - qCore.js (qJSLib)
   
    @Notes:
     - 
   
    @Todo:
     - 
*/   

    var iInter=10, iCtr=iInter, _wT, _wB, bdT, bdB
    bDebug=true
    __load_interval = setInterval("start_to()",50)
    
//winTest(window.frames["winCtr"])
    
    
//    window.onerror=""
    HTML_BUTTON_COMMON = "<input class=button type=button name=~1 value='~2' onclick='~3' onmouseover='this._bkgc_bk=this.style.backgroundColor; this.style.backgroundColor=\"#CECFC2\"' onmouseout='this.style.backgroundColor = this._bkgc_bk' style='color: #555; background: #dddecb; font: bold 13px arial; border: 1px solid #aaa; cursor: hand; cursor: pointer'>"
__i=0
    
    function start_to(){
window.status=(++__i)
//debug(
//    "\n winTest(winCtr) = "+winTest(window.frames["winCtr"])
//   +"\n winTest(winBody) = "+winTest(window.frames["winBody"])
//   +"\n winTest(_wo) = "+winTest(_wo)
//)
        if(winTest(window.frames["winCtr"]) && winTest(window.frames["winBody"]) && winTest(_wo)){
            clearInterval(__load_interval)
            setTimeout("start_ready()",50);
            return;
        }
    }
    function start_ready(){
        var stT, stB,sTitle=""
        try{sTitle=getTitleElem(_wo).innerHTML}catch(x){}
        try {
            _wT=window.frames["winCtr"]
            _wB=window.frames["winBody"]        
            bdT=_wT.document.body;stT=bdT.style
            bdB=_wB.document.body;stB=bdB.style
            stT.padding=stT.margin="0px"
            stB.padding=stB.padding="0px"
            stT.fontFamily="'Comic Sans MS',arial"; stB.fontSize="10pt"
            stB.fontFamily="'Bitstream Vera Sans Mono','lucida console',arial"; stB.fontSize="9pt"
            stT.backgroundColor=stB.backgroundColor="navy"
            stT.color=stB.color="yellow"
            bdT.innerHTML+=(
                "<div id=divClearButton style='position: absolute; top: 1; right: 1'>"
    //            	+"<input type=button value=Clear onclick='window.top.btPress(\"clear\")'>"
                    +(HTML_BUTTON_COMMON.format("btClear", "Clear", "window.top.btPress(\"clear\")"))
                +"</div><div id=divTitle  align=center style='margin: 1px 0px 0px 3px ;position: absolute; top: 2; font: 13px bold arial; color: orange'>qConsole"+(sTitle?" ("+sTitle+")":"")+"</div>"
            )
            bdB.innerHTML+="[ loaded - "+qGetTimeWithMS()+" ]<br>"
            if(_wo)try{_wo.focus()}catch(x){}
            if(_wo&&_w.oURI&&oURI.getParam("Callback")){ try{ _wo.consoleLoaded() }catch(e){} }
        }catch(x){
            alert("start_ready: "+ x.message); throw x
        }
    }
    function pCons(s){ 
//        bdB.innerHTML+=(s$(s).replace(/ /g, "&nbsp;").replace(/\n/g, "<br>"))+"<br>"
        bdB.innerHTML+="<div style='white-space: nowrap'>"+(s$(s).replace(/ /g, "&nbsp;").replace(/\n/g, "<br>"))+"</div>"
        try{
            if(_w._scrTO)clearTimeout(_w._scrTO)
            _scrTO=setTimeout("_wB.scroll(0,10000)",50)
        }catch(x){
            alert("pCons Failed: "+ x.message); throw x
        }
    }
    function btPress(sAction){
        if(sAction=="clear"){
            bdB.innerHTML=""
        } 
    }
    function clearCons(){bdB.innerHTML=""}
